package com.dminvoicemanager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class DM_Discover_GPS extends Activity{
	SQLiteDatabase mydb;
	static String DATABASE_NAME = "dminvoicemanager.db";
	static String LOCATION_DB = "fRepGps";
	static String USER_DB = "fUserGps";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dm_discover_gps);
		listCurrentLocations();
	}
	private void listCurrentLocations() {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
				ListView lvtypedes = (ListView) findViewById(R.id.list_view_gps);
				String[] fromtrdes = new String[] { "item_result_1", "item_result_2",
						"item_result_3" };
				int[] totrdes = new int[] { R.id.event_time, R.id.longitude,
						R.id.latitude };
				// prepare the list of all records
				List<HashMap<String, String>> fillMapstrdes = new ArrayList<HashMap<String, String>>();
				
				mydb = openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null);
				Cursor allrowitemsdes = null;
				try {
					String query = "SELECT _id,device_time,longitude,latitude FROM fRepGps";
					allrowitemsdes = mydb.rawQuery(query, null);
				} catch (Exception e) {
				}
				if (allrowitemsdes != null) {
					if (allrowitemsdes.getCount() > 0) {
						while (allrowitemsdes.moveToNext()) {
							String record_id = allrowitemsdes.getString(0);
							String device_time = allrowitemsdes.getString(1);
							String longitude = allrowitemsdes.getString(2);
							String latitude = allrowitemsdes.getString(3);
							HashMap<String, String> maptrdes = new HashMap<String, String>();
							maptrdes.put("item_result_1", record_id + ") " +device_time);
							maptrdes.put("item_result_2", longitude);
							maptrdes.put("item_result_3", latitude);
							fillMapstrdes.add(maptrdes);
							
							SimpleAdapter adaptertrdes = new SimpleAdapter(this,
									fillMapstrdes, R.layout.dm_gpslist_raw,
									fromtrdes, totrdes);
							lvtypedes.setAdapter(adaptertrdes);
						}
					}
				}
				allrowitemsdes.close();
				mydb.close();
	}
}
